<?php

namespace App\Extensions\Form\Field;

use Encore\Admin\Form\Field\Table;
use Encore\Admin\Form\NestedForm;

class ETable extends Table
{
    public function prepare($input)
    {
        $form = $this->buildNestedForm($this->column, $this->builder);

        $prepare = $form->prepare($input);
        # 添加 ->values()  初始化键值，防止编辑时键值重复覆盖
        return collect($prepare)->reject(function ($item) {
            return $item[NestedForm::REMOVE_FLAG_NAME] == 1;
        })->map(function ($item) {
            unset($item[NestedForm::REMOVE_FLAG_NAME]);

            return $item;
        })->values()->toArray();
    }

}
